package com.drakulo.hi.logic.actions;

import java.util.List;

import com.dk.hi.core.exceptions.HIException;
import com.dk.hi.gui.MapActor;

/**
 * <b>Action runner in a Thread</b>
 * <p>
 * Execute an <code>Action</code> list in a thread. Blocking actions can be
 * handled here without blocking the entire game. While a blocking action is
 * still running, the process will wait for it to finish (ie a text box will not
 * vanish until the player clicked on the "OK" button.
 * </p>
 */
public class ActionRunner extends Thread {
	/**
	 * MapActor witch lunched the actions. May be null for batch actions.
	 */
	MapActor actor;

	/**
	 * Action list to execute
	 */
	List<Action> actions;

	/**
	 * Constructor
	 * 
	 * @param actor
	 *            - MapActor witch lunched the actions
	 * @param actions
	 *            - Action list to execute
	 */
	public ActionRunner(MapActor actor, List<Action> actions) {
		this.actor = actor;
		this.actions = actions;
	}

	/** {@inheritDoc} */
	@Override
	public void run() {
		for (Action action : this.actions) {
			try {
				action.run();
			} catch (HIException e) {
				e.printStackTrace();
			}
		}
	}

}
